]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
status/nightLight: Use promise to initialize proxy
authorFlorian Müllner <fmuellner@gnome.org>
Sun, 24 Jul 2022 18:12:54 +0000 (20:12 +0200)
committerMarge Bot <marge-bot@gnome.org>
Mon, 1 Aug 2022 12:33:35 +0000 (12:33 +0000)
There's no good reason for waiting for the proxy to be initialized
to connect signals. In fact, connecting the signal beforehand
ensures that the handler is in place when the proxy fetches the
properties, so we don't have to call the handler explicitly.

That in turn will allow us in a follow-up to rely on the signal
parameters to only process changed properties.

To achieve that, construct the proxy manually, and then initialize
it asynchronously in a Promise.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2391>

js/ui/status/nightLight.js

index c595c3da02ab8de31ff70efee60426b3d77d52d7..109fe6791297a6c6f467fcb8d7bac017837bb21b 100644 (file)
@@ -1,7 +1,7 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 /* exported Indicator */
 
-const { Gio, GObject } = imports.gi;
+const {Gio, GLib, GObject} = imports.gi;
 
 const Main = imports.ui.main;
 const PanelMenu = imports.ui.panelMenu;
@@ -13,7 +13,7 @@ const BUS_NAME = 'org.gnome.SettingsDaemon.Color';
 const OBJECT_PATH = '/org/gnome/SettingsDaemon/Color';
 
 const ColorInterface = loadInterfaceXML('org.gnome.SettingsDaemon.Color');
-const ColorProxy = Gio.DBusProxy.makeProxyWrapper(ColorInterface);
+const colorInfo = Gio.DBusInterfaceInfo.new_for_xml(ColorInterface);
 
 var Indicator = GObject.registerClass(
 class Indicator extends PanelMenu.SystemIndicator {
@@ -22,16 +22,17 @@ class Indicator extends PanelMenu.SystemIndicator {
 
         this._indicator = this._addIndicator();
         this._indicator.icon_name = 'night-light-symbolic';
-        this._proxy = new ColorProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
-                                     (proxy, error) => {
-                                         if (error) {
-                                             log(error.message);
-                                             return;
-                                         }
-                                         this._proxy.connect('g-properties-changed',
-                                                             this._sync.bind(this));
-                                         this._sync();
-                                     });
+
+        this._proxy = new Gio.DBusProxy({
+            g_connection: Gio.DBus.session,
+            g_name: BUS_NAME,
+            g_object_path: OBJECT_PATH,
+            g_interface_name: colorInfo.name,
+            g_interface_info: colorInfo,
+        });
+        this._proxy.connect('g-properties-changed', () => this._sync());
+        this._proxy.init_async(GLib.PRIORITY_DEFAULT, null)
+            .catch(e => console.error(e.message));
 
         this._item = new PopupMenu.PopupSubMenuMenuItem("", true);
         this._item.icon.icon_name = 'night-light-symbolic';